package de.slothsoft.commons.swing.validation;

import java.text.MessageFormat;

import javax.swing.text.JTextComponent;

import de.slothsoft.commons.res.CommonMessages;

public class MandatoryTextComponentTester<S extends JTextComponent> implements
		ITester<S> {

	@Override
	public boolean acceptInput(JTextComponent source) {
		String text = source.getText();
		if (text == null || text.trim().length() == 0)
			return false;
		return true;
	}

	@Override
	public String getErrorMessage(String sourceName) {
		return MessageFormat.format(
				CommonMessages.getString("Validator.mandatory"), sourceName);
	}

}
